package svgedit.gui;

/*
 * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 *
 *   - Neither the name of Oracle or the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

import java.awt.BorderLayout;

import java.awt.Point;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;

import svgedit.gui.actions.ChooseColorAction;

/**
 * A class that shows the colour chooser dialog and modifications
 * 
 * @author SARJ
 * 
 */
public class ColorChooser extends JDialog
// implements ChangeListener
{
	private static final long serialVersionUID = -4190512383676133371L;
	public static final int FILL_OPTION = 100;
	public static final int STROKE_OPTION = 200;

	protected JColorChooser tcc;

	// The box to send the color too
	private JButton colorPreviewBox;

	/**
	 * Construct the color dialog
	 * 
	 * @param frame
	 *            The app frame
	 * @param colorPreviewBox2
	 *            THe button to show the colour on - in toolbar
	 * @param opt
	 *            If stroke or fill
	 */
	public ColorChooser(JFrame frame, JButton colorPreviewBox2, int opt)
	{
		super(frame, true);
		this.colorPreviewBox = colorPreviewBox2;

		JPanel jpPanel = new JPanel(new BorderLayout());

		// Set up color chooser for setting text color
		tcc = new JColorChooser();
		tcc.getSelectionModel().addChangeListener(
				new ChooseColorAction(colorPreviewBox, tcc, opt));
		tcc.setBorder(BorderFactory.createTitledBorder("Choose Text Color"));

		jpPanel.add(tcc, BorderLayout.PAGE_END);

		// Add the none button to colour chooser up top
		JPanel jpNone = new JPanel();
		JButton jbtNone = new JButton("None");
		jbtNone.addActionListener(new ChooseColorAction(colorPreviewBox, tcc,
				opt, this));

		jpNone.add(jbtNone);

		jpPanel.add(jpNone, BorderLayout.NORTH);

		add(jpPanel);

		this.pack();

		// Set Location
		Point point = new Point(colorPreviewBox2.getLocationOnScreen());
		point.x -= (getWidth() / 2);
		point.y += 20;
		setLocation(point);

		this.setVisible(true);

	}

}
